package com.foreknow.domo7;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class Master {
    public void cure(Pet pet) { //pet = Penguin
        if(pet.getHealth() < 50) {
           pet.toHospital();
        }
    }

    public void feed(Pet pet) {
        pet.eat();
    }

    public void play(Pet pet) {//pet = Dog
        if(pet instanceof Dog) { //instanceof作用：如果Dog是Pet的子类返回值为true，否则为false
            Dog dog = (Dog) pet;
            dog.game();
        }else if(pet instanceof Penguin) {
            Penguin penguin = (Penguin) pet;
            penguin.swimming();
        }
    }

    public static void main(String[] args) {

        Master master = new Master();
        Dog p = new Dog(); //父类的引用指向子类的对象
        p.setHealth(40);
        master.cure(p);
        master.feed(p);
        master.play(p);

        Penguin p1 = new Penguin();
        p1.setHealth(30);
        master.cure(p1);
        master.feed(p1);
        master.play(p1);


        //继承多态在实际中如何使用
        try {
//            Reader reader = new FileReader("");
            BufferedReader bufferedReader = new BufferedReader(new FileReader(""));
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }







//        Master master = new Master();
//        Dog dog = new Dog();
//        dog.setName("大黄");
//        dog.setHealth(40);
//        dog.setLove(100);
//
//        Penguin penguin = new Penguin();
//        penguin.setName("QQ");
//        penguin.setHealth(20);
//        penguin.setLove(90);
//
//        master.cure(dog);
//        master.cure(penguin);
    }
}
